package com.chatdating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chatdating.entity.Comment;
import com.chatdating.mapper.CommentMapper;
import com.chatdating.service.CommentService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Collections;
import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Override
    public List<Comment> getCommentsByPostId(Long postId) {
        return baseMapper.findByPostId(postId);
    }

    @Override
    public Comment addComment(Comment comment) {
        baseMapper.insert(comment);
        return comment;
    }

    @Override
    public Page<Comment> pageCommentsByPostId(Page<Comment> page, Long postId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("post_id", postId);
        queryWrapper.orderByDesc("create_time");
        return baseMapper.selectPage(page, queryWrapper);
    }

    @Override
    public Integer getCommentCountByPostId(Long id) {
        return baseMapper.getCommentCountByPostId(id);
    }

    @Override
    public void delComment(Integer id) {
        baseMapper.delComment(id);
    }

    @Override
    public List<Comment> getCommentList(Integer pid) {
        return baseMapper.getCommentList(pid);
    }
}
